package java6681.lesson03;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.Locale;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请按yyyy-MM-dd的格式输入开班日期：");
        String date = sc.nextLine();
        System.out.println("培训时间15天，结业日期：" + calc6681(date));
    }

    public static String calc6681(String date) {
        date = date.trim().replaceAll(" ", "");
        //培训时间
        final int trainingTime = 15;
        TemporalAccessor temp;
        String strPattern = "yyyy-MM-dd";
        if ("".equals(date)) {
            return null;
        } else {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(strPattern);
            try {
                temp = formatter.parse(date);
                //获取输入当天的天数
                int day = Integer.parseInt(date.substring(date.length() - 2));
                LocalDate localDate = LocalDate.from(temp);
                TemporalAdjuster ta = TemporalAdjusters.lastDayOfMonth();
                //判断最后一天
                int endday = localDate.with(ta).getDayOfMonth();
                if (endday < day) {
                    return null;
                }
                //加天数
                localDate = localDate.plusDays(trainingTime);
                return localDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日 EEE", Locale.CHINESE));
            } catch (Exception e) {
                return null;
            }
        }


    }
}
